<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <base data-ice="baseUrl" href="../../">
  <title data-ice="title">Math3d/Circle.js | webpack-demo1</title>
  <link type="text/css" rel="stylesheet" href="css/style.css">
  <link type="text/css" rel="stylesheet" href="css/prettify-tomorrow.css">
  <script src="script/prettify/prettify.js"></script>
  <script src="script/manual.js"></script>
</head>
<body class="layout-container" data-ice="rootContainer">

<header>
  <a href="./">Home</a>
  
  <a href="identifiers.html">Reference</a>
  <a href="source.html">Source</a>
  
  <div class="search-box">
  <span>
    <img src="./image/search.png">
    <span class="search-input-edge"></span><input class="search-input"><span class="search-input-edge"></span>
  </span>
    <ul class="search-result"></ul>
  </div>
</header>

<nav class="navigation" data-ice="nav"><div>
  <ul>
    
  <li data-ice="doc"><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/Math3d/Circle.js~Circle.html">Circle</a></span></span></li>
<li data-ice="doc"><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/Math3d/CircleAndPoint.js~CircleAndPoint.html">CircleAndPoint</a></span></span></li>
<li data-ice="doc"><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/Math3d/Common.js~Common.html">Common</a></span></span></li>
<li data-ice="doc"><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/Math3d/Line.js~Line.html">Line</a></span></span></li>
<li data-ice="doc"><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/Math3d/LineAndCircle.js~LineAndCircle.html">LineAndCircle</a></span></span></li>
<li data-ice="doc"><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/Math3d/LineAndPoint.js~PointAndLine.html">PointAndLine</a></span></span></li>
<li data-ice="doc"><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/Math3d/Point.js~Point.html">Point</a></span></span></li>
<li data-ice="doc"><span data-ice="kind" class="kind-variable">V</span><span data-ice="name"><span><a href="variable/index.html#static-variable-EPSILON">EPSILON</a></span></span></li>
</ul>
</div>
</nav>

<div class="content" data-ice="content"><h1 data-ice="title">Math3d/Circle.js</h1>
<pre class="source-code line-number raw-source-code"><code class="prettyprint linenums" data-ice="content">import { EPSILON } from &apos;./Const.js&apos;
import Point from &apos;./Point.js&apos;
export default class Circle{
  /**
   * &#x751F;&#x6210;3&#x70B9;&#x5706;
   * @param {*} p1
   * @param {*} p2
   * @param {*} p3
   */
  static getThreePointCircle(_p1, _p2, _p3, plane = &quot;xoy&quot;) {
    let p1;
    let p2;
    let p3;

    // &#x5224;&#x65AD;&#x662F;&#x5426;&#x5171;&#x7EBF;
    let isCollinear = Point.area(
      new THREE.Vector3(_p1.x, _p1.y, _p1.z),
      new THREE.Vector3(_p2.x, _p2.y, _p2.z),
      new THREE.Vector3(_p3.x, _p3.y, _p3.z),
    )
    if (isCollinear==0) {
      return null
    }

    if (plane == &quot;xoy&quot;) {
      p1 = _p1
      p2 = _p2
      p3 = _p3
    } else if (plane == &quot;xoz&quot;) {
      p1 = {
        x: _p1.x,
        y: _p1.z
      }
      p2 = {
        x: _p2.x,
        y: _p2.z
      }
      p3 = {
      x: _p3.x,
      y: _p3.z
      }
    }
    let a,a1,b,b1,ry;
    let ret = { x: 0.0, y: 0.0, r: 0.0 };

    let m = {x:0.0,y:0.0};
    let m1 = {x:0.0,y:0.0};
    let c = {x:0.0,y:0.0};

    m.y = (p1.y+p2.y) / 2;
    m.x = (p1.x+p2.x) / 2;
    m1.x = (p2.x+p3.x) / 2;
    m1.y = (p2.y+p3.y) / 2;

    a= (p1.y - p2.y)/(p1.x - p2.x + EPSILON);
    b = m.y + (m.x/(a+EPSILON));

    a1= (p2.y - p3.y)/(p2.x - p3.x + EPSILON);
    b1 = m1.y + (m1.x/(a1+EPSILON));

    let inva = 1/(a+EPSILON);
    let  inva1 = 1/(a1+EPSILON);

    c.x = (b1 - b) / (inva1 - inva + EPSILON);
    c.y =  -(c.x/(a+EPSILON)) + b;

    ry = Math.sqrt((p1.x-c.x)*(p1.x-c.x)+(p1.y-c.y)*(p1.y-c.y));

    ret.x = c.x;
    ret.y = c.y;
    ret.r = ry;

    if (plane == &quot;xoy&quot;) {
      return {
        center: {
          x: ret.x,
          y: ret.y,
          z: _p1.z
        },
        radius: ret.r
      }
     } else if (plane == &quot;xoz&quot;) {
      return {
        center: {
          x: ret.x,
          y: _p1.y,
          z: ret.y,
        },
        radius: ret.r
      }
    }
  }

   /**
     * &#x8BA1;&#x7B97;&#x4E24;&#x4E2A;&#x5706;&#x7684;&#x4EA4;&#x70B9;,&#x53EA;&#x80FD;&#x8BA1;&#x7B97;xoy&#x5E73;&#x9762;&#x4E0A;&#x7684;
     * todo: &#x52A0;&#x4E0A;&#x5706;&#x7684;&#x6CD5;&#x7EBF;,&#x652F;&#x6301;&#x4E09;&#x7EF4;&#x4EA4;&#x70B9;&#x68C0;&#x6D4B;
     * @param {*} c1
     * @param {*} r1
     * @param {*} c2
     * @param {*} r2
     */
    static circleAndCircleIntersec(c1, r1, c2, r2) {
        // &#x4E24;&#x4E2A;&#x5706;&#x5FC3;&#x7684;&#x8DDD;&#x79BB;
        let c1c2 = c2.clone().sub(c1)
        if (c1c2.length &gt; r1 + r2) {
            return null
        }

        // &#x6839;&#x636E;&#x4F59;&#x5F26;&#x5B9A;&#x7406;
        let a = r2
        let b = r1
        let c = c1c2.length()
        let cosA = (b * b + c * c - a * a) / (2 * b * c)
        if (!Math3D.isTriangle(a, b, c)) return null

        let A = Math.acos(cosA)

        let rotation = c1c2.clone().normalize().multiplyScalar(r1)
        let ret = []
        ret[0] = rotation.clone().applyAxisAngle(new THREE.Vector3(0, 0, 1), A).add(c1)
        ret[1] = rotation.clone().applyAxisAngle(new THREE.Vector3(0, 0, 1), -A).add(c1)
        return ret
    }

    /**
     * &#x6700;&#x5C0F;&#x5706;&#x8986;&#x76D6;
     * todo: &#x5706;&#x5FC3;&#x786E;&#x5B9A;&#x4E0D;&#x51C6;&#x786E;
     */
    static getIdentityCircleCoverage(posArr) {
        let p = posArr
        let R = 2
        let ret = 1
        let alp = []

        let center = null
        for (let i = 0; i &lt; p.length; i++) {
            let t = 0;
            for (let j = 0; j &lt; p.length; j++) {
                let D = p[i].distanceTo(p[j])
                if (i != j &amp;&amp; D &lt;= 2 * R) {
                    let mid = Math3D.circleAndCircleIntersec(p[i], 1, p[j], 1)
                    alp[t] = {}
                    alp[t + 1] = {}

                    let phi = Math.acos(D / 2.0 / R);
                    let theta = Math.atan2(p[j].y - p[i].y, p[j].x - p[i].x);
                    // &#x7528;&#x4E24;&#x4E2A;&#x6781;&#x89D2;&#x8868;&#x793A;&#x5706;&#x5F27;
                    alp[t].v = theta - phi
                    // &#x662F;&#x5426;&#x662F;&#x5706;&#x5F27;&#x7684;&#x8D77;&#x59CB;&#x70B9;
                    alp[t].flag = true
                    mid &amp;&amp; Array.isArray(mid) &amp;&amp; (alp[t].center = mid[1])


                    alp[t + 1].v = theta + phi
                    alp[t + 1].flag = false
                    t += 2
                }
            }

            // &#x4ECE;&#x5C0F;&#x5230;&#x5927;&#x6392;&#x5E8F;
            alp.sort(function (a, b) { return a.v - b.v })
            let sum = 1;

            for (let m = 0; m &lt; t; m++) {
                if (alp[m].flag) sum++;
                else sum--;

                if (sum &gt; ret) {
                    ret = sum
                    alp[m].center &amp;&amp; (center = alp[m].center)
                }
            }
        }
        console.error(ret, center)
        return center
    }
}
</code></pre>

</div>

<footer class="footer">
  Generated by <a href="https://esdoc.org">ESDoc<span data-ice="esdocVersion">(1.1.0)</span><img src="./image/esdoc-logo-mini-black.png"></a>
</footer>

<script src="script/search_index.js"></script>
<script src="script/search.js"></script>
<script src="script/pretty-print.js"></script>
<script src="script/inherited-summary.js"></script>
<script src="script/test-summary.js"></script>
<script src="script/inner-link.js"></script>
<script src="script/patch-for-local.js"></script>
</body>
</html>
